﻿// <copyright file="StringExtensions.cs" company="KodefuGuru">
// Microsoft Public License (Ms-PL)
// </copyright>
// <author>Chris Eargle</author>
// <email>kodefuguru@live.com</email>
// <date>2009-12-27</date>
// <summary>String Web Extensions</summary>
namespace Fluent
{
    using System.ComponentModel;
    using System.Diagnostics.CodeAnalysis;
    using System.Web;

    /// <summary>
    /// Web extension methods for <see cref="System.String"/>. 
    /// </summary>
    [Browsable(false)]
    [EditorBrowsable(EditorBrowsableState.Never)]
    public static class StringExtensions
    {
        /// <summary>
        /// Minimally converts the source string to an HTML-encoded string.
        /// </summary>
        /// <param name="html">The string to encode.</param>
        /// <returns>An encoded string.</returns>
        public static string HtmlAttributeEncode(this string html)
        {
            return HttpUtility.HtmlAttributeEncode(html);
        }

        /// <summary>
        /// Converts the source string that has been HTML-encoded for HTTP transmission into a decoded string.
        /// </summary>
        /// <param name="html">The string to decode.</param>
        /// <returns>A decoded string.</returns>
        public static string HtmlDecode(this string html)
        {
            return HttpUtility.HtmlDecode(html);
        }

        /// <summary>
        /// Converts the source string to an HTML-encoded string.
        /// </summary>
        /// <param name="html">The string to encode.</param>
        /// <returns>An encoded string.</returns>
        public static string HtmlEncode(this string html)
        {
            return HttpUtility.HtmlEncode(html);
        }

        /// <summary>
        /// Converts the source string that has been encoded for transmission in a URL into a decoded string.
        /// </summary>
        /// <param name="source">The string to decode.</param>
        /// <returns>A decoded string.</returns>
        [SuppressMessage("Microsoft.Design", "CA1055", Justification = "This is a pass-through method to HttpUtility.")]
        public static string UrlDecode(this string source)
        {
            return HttpUtility.UrlDecode(source);
        }

        /// <summary>
        /// Encodes a URL string.
        /// </summary>
        /// <param name="source">The string to encode.</param>
        /// <returns>An encoded string.</returns>
        [SuppressMessage("Microsoft.Design", "CA1055", Justification = "This is a pass-through method to HttpUtility.")]
        public static string UrlEncode(this string source)
        {
            return HttpUtility.UrlEncode(source);
        }

        /// <summary>
        /// Encodes the path portion of a URL string for reliable HTTP transmission from the Web server to a client.
        /// </summary>
        /// <param name="source">The text to URL-encode.</param>
        /// <returns>The URL-encoded text.</returns>
        [SuppressMessage("Microsoft.Design", "CA1055", Justification = "This is a pass-through method to HttpUtility.")]
        public static string UrlPathEncode(this string source)
        {
            return HttpUtility.UrlPathEncode(source);
        }
    }
}
